#if 0
#ifdef WIN32

#include "Engine.h"
#include "Object.h"
#include "Draw.h"

// ---------------------------------------------------------------
static Engine* engine = NULL;
// ---------------------------------------------------------------
Engine::Engine(void)
    :
#ifdef WIN32
    	hwnd(NULL), hRC(NULL), hDC(NULL),
#endif
    running(false), width(512), height(512), imageID(0), objetos()
{
    engine = this;
}
// ---------------------------------------------------------------
Engine::~Engine(void)
{
    shutdown();
}
// ---------------------------------------------------------------
Object& Engine::addObject(void)
{
    Object obj;
    objetos.push_back(obj);
    return objetos[objetos.size()-1];
}
// ---------------------------------------------------------------
int Engine::loadTexture( const char* filename )
{
    return ilutGLLoadImage( (char*) filename);
}
// ---------------------------------------------------------------
void Engine::loop(void)
{
#ifdef WIN32
    MSG msg;
    running = true;

    while ( running )
    {
        /* check for messages */
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            /* handle or dispatch messages */
            if (msg.message == WM_QUIT)
            {
                running = false;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        else
        {
            //
            RECT rect;
            GetClientRect( hwnd, &rect );
            width  = rect.right - rect.left;
            height = rect.bottom - rect.top;
            resizeWindow(width,height);

            drawScene();
        }
    }
#else

#endif
}
// ---------------------------------------------------------------
bool Engine::init(void* hInstance)
{
	bool ok = true;
#ifdef WIN32
	ok =  (hwnd == NULL);
#endif

    if( ok )
    {
#ifdef WIN32
    	// cria a janela no Windows
        if( !Engine::createWindowClass( (HINSTANCE) hInstance) )
            return false;

        // cria a janela
        width = height = 512;
        hwnd = CreateWindowEx(0,
                              "GLWindowClassName",
                              "MFPJ - Baby Engine",
                              WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT,
                              CW_USEDEFAULT,
                              width,
                              height,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);

        ShowWindow(hwnd, 1);

        /* enable OpenGL for the window */
        enableOpenGL();
#else
        // TODO criar janela no Linux

#endif





        // OpenIL
        ilutRenderer(ILUT_OPENGL);
        ilInit();
        iluInit();
        ilutInit();
        ilutRenderer(ILUT_OPENGL);

        ilGenImages( 1, &imageID );
        ilBindImage( imageID );

        return true;
    }

    return true;
}
// ---------------------------------------------------------------
void Engine::enableOpenGL(void)
{
#ifdef WIN32
    PIXELFORMATDESCRIPTOR pfd;

    int iFormat;

    /* get the device context (DC) */
    hDC = GetDC(hwnd);

    /* set the pixel format for the DC */
    ZeroMemory(&pfd, sizeof(pfd));

    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW |
                  PFD_SUPPORT_OPENGL |
                  PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;

    iFormat = ChoosePixelFormat(hDC, &pfd);

    SetPixelFormat(hDC, iFormat, &pfd);

    /* create and enable the render context (RC) */
    hRC = wglCreateContext(hDC);

    wglMakeCurrent(hDC, hRC);
#endif
}
// ---------------------------------------------------------------
void Engine::shutdown(void)
{
    ilDeleteImage( imageID );
     imageID = 0;

    // OpenIL
    ilShutDown();

    //dtor
#ifdef WIN32
    if( hRC )
    {
        wglMakeCurrent(NULL, NULL);
        wglDeleteContext(hRC);
        hRC = NULL;
    }

    if( hwnd && hDC )
    {
        ReleaseDC(hwnd, hDC);
        hDC = NULL;
    }

    /* destroy the window explicitly */
    if(hwnd)
    {
            DestroyWindow(hwnd);
            hwnd = NULL;
    }
#else
    // TODO fazer o mesmo no Linux
#endif
}

static float px = 0, py = 0;

#ifdef WIN32
// ---------------------------------------------------------------
LRESULT CALLBACK Engine::windowProcCallback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    RECT rect;

    switch (uMsg)
    {
        case WM_CLOSE:
            PostQuitMessage(0);
        break;

        case WM_DESTROY:
            return 0;
        case WM_PAINT:
            engine->drawScene();
            return 0;
        break;
        case WM_SIZE:
        // Check to see if we are losing or gaining our window.  Set the
        // active flag to match
        if( SIZE_MAXHIDE == wParam || SIZE_MINIMIZED == wParam )
        {

        }else
        {
            int width, height;
            GetClientRect( hwnd, &rect );

            width  = rect.right - rect.left;
            height = rect.bottom - rect.top;

            engine->resizeWindow(width,height);
            return 0;
        }
        break;

        case WM_KEYDOWN:
        {
            switch (wParam)
            {
                case VK_ESCAPE:
                    PostQuitMessage(0);
                break;
            }
            return TRUE;
        }
        break;
        case WM_KEYUP:
        {
            switch (wParam)
            {
                case VK_ESCAPE:
                    PostQuitMessage(0);
                break;
            }
            return 0;
        }
        break;

        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }

    return 0;

}
// ---------------------------------------------------------------
void Engine::resizeWindow( unsigned int _width, unsigned int _height )
{
    width  = _width;
    height = _height;

    glViewport(0,0,width, height);

    // NOTA: melhora o desempenho
    //glEnable(GL_SCISSOR_TEST);
    //glScissor( 0,0, width, height);


    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();    // rescala o Y
    float sy = (height) ? ((float)width/(float)height): 1.0f;
    glScalef( 1.0f, sy, 1.0f);
    glMatrixMode(GL_MODELVIEW);
}
// ---------------------------------------------------------------
bool Engine::createWindowClass(HINSTANCE hInstance)
{
    static int status = 0; // 0 --> n�o chamado, 1 --> ok, -1 erro
    if( status == 0 )
    {
        WNDCLASSEX wcex;

        /* register window class */
        wcex.cbSize = sizeof(WNDCLASSEX);
        wcex.style = CS_OWNDC;
        wcex.lpfnWndProc = windowProcCallback;
        wcex.cbClsExtra = 0;
        wcex.cbWndExtra = 0;
        wcex.hInstance = hInstance;
        wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
        wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
        wcex.lpszMenuName = NULL;
        wcex.lpszClassName = "GLWindowClassName";
        wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;

        if (!RegisterClassEx(&wcex))
        {
            status = -1;
        }
        else
        {
            status = +1;
        }
    }

    return status > 0; //sucesso
}
#endif
// ---------------------------------------------------------------
void Engine::drawScene(void)
{
    static float theta =0;

    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();

    for( unsigned int i=0; i<objetos.size() ; ++i )
    {
        glPushMatrix();
            glLoadIdentity();
            objetos[i].draw();
        glPopMatrix();
    }

    static Material opaco;
    opaco.cor.set(0.75f,1,0.75f,0.9f);
    opaco.texturaHabilitada = false;
    opaco.usarMaterial();

    static float angle = 45;

#ifdef WIN32
    if( GetAsyncKeyState(VK_RIGHT) ) px += 0.01;
    if( GetAsyncKeyState(VK_LEFT ) ) px -= 0.01;
    if( GetAsyncKeyState(VK_UP   ) ) py += 0.01;
    if( GetAsyncKeyState(VK_DOWN ) ) py -= 0.01;
#endif
    //if( Getkeys(VK_UP ) ) py += 0.001;
    //if( GetAsyncKeyState(VK_DOWN ) ) py -= 0.001;


    //Draw::drawCircle( Vetor2d(0,0), 0.5, 8 );
    Draw::drawEllipse( Vetor2d(0.25,0.25), 0.5, 0.8, 20 );

    glColor4f(0,0.3,0,0.25f);
    Draw::drawArc( Vetor2d(0.25,0.25), 0.2,  angle, 145 );

    angle += 0.6f;

    glFlush();
#ifdef WIN32
    SwapBuffers(hDC);
#else
    // TODO disparar a troca dos buffers no windows
#endif

    theta += 1.0f;
    //Sleep (1);
}
// ---------------------------------------------------------------
void Engine::drawQuad(void)
{
    // TODO dar uma cor
    glBegin(GL_QUADS);
        //glColor3f(1.0f, 1.0f, 1.0f);
        //const Cor& cor = Cor::COLOR_GREEN;
        //glColor4f( cor.r, cor.g, cor.b, cor.a );

        glTexCoord2f(0.0f,0.0f);        glVertex2f( -1.0f, -1.0f);
        glTexCoord2f(1.0f,0.0f);        glVertex2f( +1.0f, -1.0f);
        glTexCoord2f(1.0f,1.0f);        glVertex2f( +1.0f, +1.0f);
        glTexCoord2f(0.0f,1.0f);        glVertex2f( -1.0f, +1.0f);

    glEnd();
}
// ---------------------------------------------------------------
#endif
#endif
